using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Design;
using System.Windows.Forms;
using System.ComponentModel;

namespace Skywave.Windows.Forms
{
    internal class DataSheetPropertyEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                return UITypeEditorEditStyle.Modal;
            }
            return base.GetEditStyle(context);
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context == null || context.Instance == null || provider == null) return value;
            SheetEditorForm editorForm = new SheetEditorForm();
            editorForm.DataSheet = (Sheet)value;
            editorForm.ShowDialog();
            ((SheetBox)context.Instance).Refresh();
            return value;
            //ComponentEditorForm pW = (ComponentEditorForm)provider.GetService(typeof(ComponentEditorForm));
            //if (pW == null) return value;
            //pW.ShowDialog();
            //return base.EditValue(context, provider, value);
        }
    }
}
